package feed;

public class ItemManager {
	static final int MAXN = 10;
	String[] types;
	int[] amounts;
	int pointer;
	public ItemManager() {
		types = new String[MAXN];
		amounts = new int[MAXN];
		pointer = 0;
	}
	public void addNew(String name, int amount) {
		if (pointer == MAXN) return;
		types[pointer] = name;
		amounts[pointer] = amount;
		++pointer;
	}
	public void modify(String name, int amount) {
		for (int i=0; i<pointer; ++i)
			if (types[i].equals(name)) {
				amounts[i] = amount;
				return;
			}
	}
	public void add(String name) {
		for (int i=0; i<pointer; ++i)
			if (types[i].equals(name)) {
				if (amounts[i] < 999)
					++amounts[i];
				return;
			}
		addNew(name, 1);
	}
	public void minus(String name) {
		for (int i=0; i<pointer; ++i)
			if (types[i].equals(name)) {
				if (amounts[i] > 0)
					--amounts[i];
				return;
			}
	}
	public int getAmount(String name) {
		for (int i=0; i<pointer; ++i)
			if (types[i].equals(name))
				return amounts[i];
		return 0;
	}
	public String[] getAllItem() {
		String[] newS = new String[pointer];
		for (int i=0; i<pointer; ++i)
			newS[i] = types[i];
		return newS;
	}
	public String getName(int index) {
		return types[index];
	}
}
